import fetch from 'utils/fetch';
import Cookies from 'js-cookie';

export function getList(requestParams) {
  const operatorid = Cookies.get('uid');
  const lastlogincode = Cookies.get('lastlogincode')
  Object.assign(requestParams, { operatorid, lastlogincode });
  return fetch({
    url: '/trc-service-enterprise/enterprise/queryAllEnterprise',
    method: 'post',
    data: JSON.stringify(requestParams),
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 根据企业ID查询企业信息
export function getEnterpriseInfoById(requestParams) {
  const operatorid = Cookies.get('uid');
  const lastlogincode = Cookies.get('lastlogincode')
  Object.assign(requestParams, { operatorid, lastlogincode });
  return fetch({
    url: '/trc-service-enterprise/enterprise/queryAllEnterprise',
    method: 'post',
    data: JSON.stringify(requestParams),
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

export function getNoEnterpriseUserList() {
  const getParams = new URLSearchParams();
  getParams.append('operatorid', Cookies.get('uid'));
  getParams.append('lastlogincode', Cookies.get('lastlogincode'));
  return fetch({
    url: '/trc-service-enterprise/enterprise/queryUserIsNotBindingEnterprise',
    method: 'get',
    params: getParams,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
}

// 新增保存企业信息
export function saveEnterpriseInfo(requestParams) {
  const operatorid = Cookies.get('uid');
  const lastlogincode = Cookies.get('lastlogincode')
  Object.assign(requestParams, { operatorid, lastlogincode });
  return fetch({
    url: '/trc-service-enterprise/enterprise/addEnterprise',
    method: 'post',
    data: JSON.stringify(requestParams),
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 修改企业信息
export function updateEnterpriseInfo(requestParams) {
  const operatorid = Cookies.get('uid');
  const lastlogincode = Cookies.get('lastlogincode')
  Object.assign(requestParams, { operatorid, lastlogincode });
  return fetch({
    url: '/trc-service-enterprise/enterprise/updateEnterprise',
    method: 'post',
    data: JSON.stringify(requestParams),
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 审核企业信息
export function auditEnterprise(requestParams) {
  const operatorid = Cookies.get('uid');
  const lastlogincode = Cookies.get('lastlogincode')
  Object.assign(requestParams, { operatorid, lastlogincode });
  return fetch({
    url: '/trc-service-enterprise/enterprise/auditEnterprise',
    method: 'post',
    data: JSON.stringify(requestParams),
    headers: {
      'Content-Type': 'application/json'
    }
  });
}

// 删除企业信息
export function deleteEnterprise(requestParams) {
  const operatorid = Cookies.get('uid');
  const lastlogincode = Cookies.get('lastlogincode')
  Object.assign(requestParams, { operatorid, lastlogincode });
  return fetch({
    url: '/trc-service-enterprise/enterprise/deleteEnterprise',
    method: 'post',
    data: JSON.stringify(requestParams),
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 恢复企业回收站档案
export function enterpriseRecycle(requestParams) {
  const operatorid = Cookies.get('uid');
  const lastlogincode = Cookies.get('lastlogincode')
  Object.assign(requestParams, { operatorid, lastlogincode });
  return fetch({
    url: '/trc-service-enterprise/enterprise/recoverEnterpriseByRecycleBin',
    method: 'post',
    data: JSON.stringify(requestParams),
    headers: {
      'Content-Type': 'application/json'
    }
  })
}

// 查询企业状态
export function enterpriseStatus() {
  const getParams = new URLSearchParams();
  getParams.append('operatorid', Cookies.get('uid'));
  getParams.append('lastlogincode', Cookies.get('lastlogincode'));
  return fetch({
    url: '/trc-service-enterprise/enterprise/commons/queryAllEnterpriseStatus',
    method: 'get',
    params: getParams,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  });
}
